
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>login</title>
    <script type="text/javascript" src="<%=request.getContextPath()%>/common/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/common/layui/css/layui.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/common/login.css">
    <script src="<%=request.getContextPath()%>/common/layui/layui.js"></script>
</head>
<body>
<div class="wrap">
    <img src="./common/imgs/back.png" class="imgStyle">
    <div class="loginForm">
        <form class="layui-form">
            <div class="logoHead">
                <!--<h2 style="margin-top: 15px">房产销售平台管理系统</h2>-->
            </div>
            <div class="usernameWrapDiv">
                <div class="usernameLabel">
                    <label>用户名:</label>
                </div>
                <div class="usernameDiv">
                    <i class="layui-icon layui-icon-username adminIcon"></i>
                    <input id="loginUsername" lay-verify="userName" class="layui-input adminInput" type="text" name="username" autocomplete="off" placeholder="输入用户名" >
                </div>
            </div>
            <div class="usernameWrapDiv">
                <div class="usernameLabel">
                    <label>密码:</label>
                </div>
                <div class="passwordDiv">
                    <i class="layui-icon layui-icon-password adminIcon"></i>
                    <input id="loginPassword" lay-verify="password" class="layui-input adminInput" type="password" name="password" placeholder="输入密码">
                </div>
            </div>

            <div class="usernameWrapDiv">
                <div class="submitLabel">
                    <label>没有账号？<a href="./register.jsp" id="loginRegister">点击注册</a></label>
                </div>
                <div class="submitDiv">
                    <input id="loginBtn" type="button" class="submit layui-btn layui-btn-primary" lay-submit lay-filter="loginForm" value="登录" />
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    layui.use(function () {
        let loginForm = layui.form;
        let layer = layui.layer;


        loginForm.verify({
            userName:function (value,item) {
                if (value.length<5){
                    return "用户名不能小于5位";
                }
                var zz = /^[A-Za-z0-9]+$/;
                if (!zz.test(value)){
                    return "用户名只能是字母和数字";
                }
            },
            password:function (value, item) {
                if (value.length<5){
                    return "密码不能小于5位";
                }
                var zz = /^[A-Za-z0-9]+$/;
                if (!zz.test(value)){
                    return "密码只能是字母和数字";
                }
            }
        })

        loginForm.on("submit(loginForm)",function (res) {
            var user = {userName:res.field.username,password:res.field.password};
            $.post({
                url:"<%=request.getContextPath()%>/login/userLogin",
                async:false,
                data:user,
                success:function (rs) {
                    if (rs.code==200){
                        if (rs.data==0){
                            location.href="home.jsp";
                        }else {
                            layer.msg(rs.msg);
                        }
                    }else {
                        layer.msg(rs.msg)
                    }
                }
            })
        })
    })
</script>
</html>
